//
//  AppleIsReviewState.m
//  邮币财富
//
//  Created by 密军李 on 2016/11/8.
//  Copyright © 2016年 王任. All rights reserved.
//

#import "AppleIsReviewState.h"

#define StationHouseHelper @""

@implementation AppleIsReviewState

- (BOOL)isAppleIsReviewState
{
    //工程影像:1278245117
    //工程影像学习版:1276902707
    //http://itunes.apple.com/cn/lookup?id=
    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/cn/lookup?id=%@",StationHouseHelper]]];
    if (data) {
        NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
        NSArray *arr = dictionary[@"results"];
        NSString *appStoryVersion = arr.firstObject[@"version"];
        NSString *currentVersion = [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"];
        //升序
        //1.4.2 < 1.4.3
        if ([appStoryVersion compare:currentVersion] == NSOrderedAscending) {
            //审核状态
            return NO;
        }else if ([appStoryVersion compare:currentVersion] == NSOrderedSame){
            //最新版本
            return YES;
        }
    }
    return NO;
}

//- (BOOL)isAppleIsReviewState
//{
//    //1232654536
//    NSString *verString=[NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://itunes.apple.com/cn/lookup?id=1278245117"] encoding:NSUTF8StringEncoding error:nil];
//    //    RLog(@"version %@",verString);
//    if (verString!=nil&&[verString length]>0&&[verString rangeOfString:@"version"].length==7) {
//        NSString *version=[[[NSBundle mainBundle]infoDictionary]objectForKey:@"CFBundleShortVersionString"];
//        NSString *appInfoOne=[verString substringFromIndex:[verString rangeOfString:@"\"version\":"].location+10];
//        appInfoOne=[[appInfoOne substringToIndex:[appInfoOne rangeOfString:@","].location]stringByReplacingOccurrencesOfString:@"\"" withString:@""];
//       // RLog(@"appInfoOne %@",appInfoOne);
//        
//        if ([appInfoOne compare:version]==NSOrderedAscending) {//
//            //审核状态
//            return NO;
//            
//        }else if ([appInfoOne compare:version]==NSOrderedSame) {
//            return YES;
//            
//        }else {
//            return YES;
//        }
//        
//    }
//    
//    return NO;
//}




@end
